package com.hhsjdesign.dynamicui.asm

import com.android.build.gradle.AppExtension
import com.android.build.gradle.AppPlugin
import com.hhsjdesign.dynamicui.asm.v1.DynamicUiTransform
import com.hhsjdesign.dynamicui.asm.v1.ScanSetting
import com.hhsjdesign.dynamicui.asm.v3.DynamicUiTransformV3
import com.hhsjdesign.dynamicui.asm.v3.ScanSettingV3
import org.gradle.api.Plugin
import org.gradle.api.Project

/**
 * 插件，可以挂在Transform，此次我需要挂在v3
 */
class DynamicUIPlugin implements Plugin<Project> {

    static int ASM_TYPE = 3
    @Override
    public void apply(Project project) {
        def isApp = project.plugins.hasPlugin(AppPlugin)
        //only application module needs this plugin to generate register code
        if (isApp) {
            Logger.make(project)
            //app
            //拿到android 拓展
            def android = project.extensions.getByType(AppExtension)

            if (ASM_TYPE == 3) {

                ArrayList<ScanSettingV3> list = new ArrayList<>(3)
                //扫描设置
                list.add(new ScanSettingV3('com.hhsjdesign.dynamicui.generate'))

                DynamicUiTransformV3.registerList = list

                //将transform 注册到 拓展中
                android.registerTransform(new DynamicUiTransformV3(project))
            }

            if (ASM_TYPE == 1) {

                ArrayList<ScanSetting> list = new ArrayList<>(3)
                //扫描设置
                list.add(new ScanSetting('com.hhsjdesign.dynamicui.generate'))

                DynamicUiTransform.registerList = list

                //将transform 注册到 拓展中
                android.registerTransform(new DynamicUiTransform(project))
            }


        }
    }
}